// Use of this source code is governed by a BSD-style license
// that can be found in the License file.

// Author: Shuo Chen (chenshuo at chenshuo dot com)
//
// This is a public header file, it must only include public header files.

#ifndef BASE_PROCESSINFO_H
#define BASE_PROCESSINFO_H

#include "string_piece.h"
#include "base_types.h"
#include "time_stamp.h"

#include <vector>
#include <sys/types.h>

NAMESPACE_START
/**
 * 处理信息抽象类
 * 记录当前
 * **/
namespace ProcessInfo
{
    pid_t pid();
    string pidString();
    uid_t uid();
    string username();
    uid_t euid();
    Timestamp startTime();
    int clockTicksPerSecond();
    int pageSize();
    bool isDebugBuild(); // constexpr

    string hostname();
    string procname();
    StringPiece procname(const string &stat);

    /// read /proc/self/status
    string procStatus();

    /// read /proc/self/stat
    string procStat();

    /// read /proc/self/task/tid/stat
    string threadStat();

    /// readlink /proc/self/exe
    string exePath();

    int openedFiles();
    int maxOpenFiles();

    struct CpuTime
    {
        double userSeconds;
        double systemSeconds;

        CpuTime() : userSeconds(0.0), systemSeconds(0.0) {}

        double total() const { return userSeconds + systemSeconds; }
    };
    CpuTime cpuTime();

    int numThreads();
    std::vector<pid_t> threads();
} // namespace ProcessInfo

NAMESPACE_END

#endif // BASE_PROCESSINFO_H
